﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HA.ModFlow.Domain.FileLayer;

namespace HA.ModFlow.Domain.DomainLayer
{

    /// <summary>
    /// 实际用到的输出控制选项，这里只有modflow部分
    /// </summary>
    [Serializable]
    public class OutputControl
    {
        public OutputControl()
        {
            _IHEDFM = FILEFORMAT._10G11_4;
            _CHEDFM = FILEFORMAT._10G11_4;
            _IDDNFM = FILEFORMAT._10G11_4;
            _CDDNFM = FILEFORMAT._10G11_4;
            _CBOUFM = FILEFORMAT._10G11_4;
            _COMPACTBUGET = false;
        }

        FILEFORMAT _IHEDFM ;

        /// <summary>
        /// 水头列表文件格式
        /// </summary>
        public FILEFORMAT IHEDFM
        {
            get { return _IHEDFM; }
            set { _IHEDFM = value; }
        }

        FILEFORMAT _CHEDFM ;
        /// <summary>
        /// 水头独立文件格式
        /// </summary>
        public FILEFORMAT CHEDFM
        {
            get { return _CHEDFM; }
            set { _CHEDFM = value; }
        }

        bool _isPrintHead = true;

        public bool IsPrintHead
        {
            get { return _isPrintHead; }
            set { _isPrintHead = value; }
        }
        bool _isPrintDD = true;

        public bool IsPrintDD
        {
            get { return _isPrintDD; }
            set { _isPrintDD = value; }
        }
        bool _isPrintBudget = true;

        public bool IsPrintBudget
        {
            get { return _isPrintBudget; }
            set { _isPrintBudget = value; }
        }
        bool _isSaveHead = true;

        public bool IsSaveHead
        {
            get { return _isSaveHead; }
            set { _isSaveHead = value; }
        }
        bool _isSaveDrawnDown = true;

        public bool IsSaveDrawnDown
        {
            get { return _isSaveDrawnDown; }
            set { _isSaveDrawnDown = value; }
        }
        bool _isSaveIBound = true;

        public bool IsSaveIBound
        {
            get { return _isSaveIBound; }
            set { _isSaveIBound = value; }
        }
        bool _isSaveBudget = true;

        public bool IsSaveBudget
        {
            get { return _isSaveBudget; }
            set { _isSaveBudget = value; }
        }
        FILEFORMAT _IDDNFM ;
        /// <summary>
        /// 降深列表文件格式
        /// </summary>
        public FILEFORMAT IDDNFM
        {
            get { return _IDDNFM; }
            set { _IDDNFM = value; }
        }

        FILEFORMAT _CDDNFM ;

        /// <summary>
        /// 降深独立文件格式
        /// </summary>
        public FILEFORMAT CDDNFM
        {
            get { return _CDDNFM; }
            set { _CDDNFM = value; }
        }

        FILEFORMAT _CBOUFM ;

        /// <summary>
        /// 边界条件输出到文件的格式
        /// </summary>
        public FILEFORMAT CBOUFM
        {
            get { return _CBOUFM; }
            set { _CBOUFM = value; }
        }


        bool _COMPACTBUGET;

        public bool COMPACTBUGET
        {
            get { return _COMPACTBUGET; }
            set { _COMPACTBUGET = value; }
        }


        /// <summary>
        /// 输出标志位
        /// </summary>
        bool _isAllStepOutput = true;

        public bool IsAllStepOutput
        {
            get { return _isAllStepOutput; }
            set { _isAllStepOutput = value; }
        }


        public POutputControl ToPack(StressPeriodCollection spc)
        {
            POutputControl oc = new POutputControl();

            oc.IHEDFM = (int)this.IHEDFM;
            oc.IDDNFM = (int)this.IDDNFM;
            oc.CHEDFM = (int)this.CHEDFM;
            oc.CDDNFM = (int)this.CDDNFM;
            oc.CBOUFM = (int)this.CBOUFM;
            oc.COMPACTBUGET = this.COMPACTBUGET ? 1 : 0;

            if (this.IsAllStepOutput == true)
            {   
                //逐应力期
                foreach (StressPeriod sp in spc.InnerList)
                {
                    SPOutput spo = new SPOutput();
                    for (int i = 0; i < sp.NSTP;i++ )
                    {
                        OutputStep os = new OutputStep();
                        os.PrintHead.BoutPut = this.IsPrintHead;
                        os.PrintDrawnDown.BoutPut=this.IsPrintDD;
                        os.PrintBudget.BoutPut = this.IsPrintBudget;
                        os.SaveHead.BoutPut = this.IsSaveHead;
                        os.SaveDrawnDown.BoutPut = this.IsSaveDrawnDown;
                        os.SaveIBound.BoutPut = this.IsSaveIBound;
                        os.SaveBudget.BoutPut = this.IsSaveBudget;
                        spo.Steps.Add(os);
                    }
                    oc.Periods.Add(spo);
                }
            }
            else
            {
                foreach (StressPeriod sp in spc.InnerList)
                {
                    SPOutput spo = new SPOutput();
                    OutputStep os = new OutputStep();
                    os.PrintHead.BoutPut = this.IsPrintHead;
                    os.PrintDrawnDown.BoutPut = this.IsPrintDD;
                    os.PrintBudget.BoutPut = this.IsPrintBudget;
                    os.SaveHead.BoutPut = this.IsSaveHead;
                    os.SaveDrawnDown.BoutPut = this.IsSaveDrawnDown;
                    os.SaveIBound.BoutPut = this.IsSaveIBound;
                    os.SaveBudget.BoutPut = this.IsSaveBudget;
                    spo.Steps.Add(os);
                   
                    oc.Periods.Add(spo);
                }
            }
            return oc;
        }
    }
}
